﻿using System;
using System.Web.Script.Services;
using System.Web.Services;

namespace AJAX_learning
{
	/// <summary>
	/// Summary description for CarService
	/// </summary>
	//[WebService(Namespace = "http://tempuri.org/")]
	//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	//[System.ComponentModel.ToolboxItem(false)]
	// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
	[ScriptService]
	public class CarService : WebService
	{
		[WebMethod]
		public int GetCarValue(string strCarMake, string strCarModel, int strCarYear)
		{
			int nReturn = 0;
			if (strCarMake == "Honda")
			{
				nReturn = strCarModel == "Pilot" ? 40000 : 30000;
			}
			else
			{
				nReturn = 20000;
			}
			int nDepreciation = (DateTime.Now.Year - strCarYear) * 2000;
			nReturn -= nDepreciation;
			return Math.Max(0, nReturn);
		}

		[WebMethod]
		public string GetTotal(string itemA, string itemB)
		{
			string ret;
			try
			{
				ret = (Convert.ToInt32(itemA) + Convert.ToInt32(itemB)).ToString();
			}
			catch (FormatException)
			{
				ret = "Format Exception";
			}
			catch(OverflowException)
			{
				ret = "Overflow Exception";
			}

			return ret;
		}
	}
}
